package com.cskaoyan.mall.service.implement;

import com.cskaoyan.mall.dao.OrderDao;
import com.cskaoyan.mall.dao.implement.OrderDaoImpl;
import com.cskaoyan.mall.model.bo.CartList;
import com.cskaoyan.mall.model.bo.ChangeOrderBO;
import com.cskaoyan.mall.model.bo.PageOrderBO;
import com.cskaoyan.mall.model.bo.SettleAccountsBO;
import com.cskaoyan.mall.model.vo.*;
import com.cskaoyan.mall.service.OrderService;

import java.util.ArrayList;
import java.util.List;

public class OrderServiceImpl implements OrderService {

    private OrderDao orderDao = new OrderDaoImpl();

    /** 动态多样的订单查询
     * 根据传入的不同参数，执行不同的查询，返回不同的结果
     * @param orderBO
     * @return
     */
    @Override
    public PageOrdersVO ordersByPage(PageOrderBO orderBO) {
        //System.out.println("进来了!");
        int totalCounts = orderDao.getTotalCounts(orderBO);
        //System.out.println(totalCounts);
        //查询当前分页的结果page1  1-5  page2  6-10  page3 11-15
        List<PageOrderInfoVO> orderInfoVOS = orderDao.ordersByPage(orderBO);
        PageOrdersVO pageOrdersVO = new PageOrdersVO();
        pageOrdersVO.setTotal(totalCounts);
        pageOrdersVO.setOrders(orderInfoVOS);
        return pageOrdersVO;
    }

    @Override
    public OrderVO order(String id) {
        OrderVO orderVO = new OrderVO();
        orderVO = orderDao.order(id);
        //对 List<StatesVO> 加数据
        orderVO.setStates();
        //订单当前状态
        //订单当前类目
        CurSpecVO curSpec = new CurSpecVO();
        curSpec.setId(orderVO.getGoodsDetailId());
        CurStateVO curState = new CurStateVO();
        curState.setId(orderVO.getState());
        orderVO.setCurState(curState);
        orderVO.setCurSpec(curSpec);
        return orderVO;
    }

    @Override
    public void changeOrder(ChangeOrderBO changeOrderBO) {
        orderDao.changeOrder(changeOrderBO);
    }

    @Override
    public void deleteOrder(String id) {
        orderDao.deleteOrder(id);
    }

    @Override
    public void settleAccounts(SettleAccountsBO accountsBO) {
        for (CartList cart:accountsBO.getCartList()
             ) {
            Integer id = cart.getId();
            Integer goodsNum = cart.getGoodsNum();
            Integer amount = cart.getAmount();
            orderDao.settleAccounts(id,goodsNum,amount);
        }
    }

    @Override
    public void pay(String id) {
        orderDao.pay(id);
    }

    @Override
    public void confirmReceive(String id) {
        orderDao.confirmReceive(id);
    }

    @Override
    public void sendComment() {
        orderDao.sendComment();
    }
}
